package sfeir.gwt.ergosum.server;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sfeir.gwt.ergosum.client.model.Address;
import sfeir.gwt.ergosum.client.model.Email;
import sfeir.gwt.ergosum.client.model.GeoLocalisation;
import sfeir.gwt.ergosum.client.model.ImageURL;
import sfeir.gwt.ergosum.client.model.NetworkItem;
import sfeir.gwt.ergosum.client.model.Person;
import sfeir.gwt.ergosum.client.model.Tel;

public class ViewProfile extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 3339316107209122925L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getPathInfo();
        if (username != null && !username.equals("/")) {
            username = username.substring(1);
            req.setAttribute("username", username);
        }
        /*
         // For Test only, create a person to display it
        Person p = testPerson(username);
        try {
            new ProfileServiceImpl().savePerson(p);
        } catch (NotLoggedInException e) {
            e.printStackTrace();
        }*/
        req.getRequestDispatcher("/ViewProfile.jsp").forward(req, resp);
    }
    
    protected Person testPerson(String username) {
        Person person = new Person();
        person.setFirstname("Patrice");
        person.setName(username);
        person.setPhoto(new ImageURL("http://www.viadeo.com/servlet/photo?memberId=002h0a0aplk6spy&ts=946681200000&type=0"));
        person.setAboutMe("About me ....");
        person.setBirthDay("03/03/1986");
        person.setCompany("SFEIR");
        person.setGeo(new GeoLocalisation(48.9, 2.07));
        List<NetworkItem> networks = new ArrayList<NetworkItem>();
        networks.add(new NetworkItem("facebook", "Facecbook.com"));
        networks.add(new NetworkItem("twitter", "twitter.com"));
        networks.add(new NetworkItem("viadeo", "viadeo.com"));
        networks.add(new NetworkItem("skype", "skype.com"));
        networks.add(new NetworkItem("vimeo", "vimeo.com"));
        networks.add(new NetworkItem("dopplr", "dopplr.com"));
        networks.add(new NetworkItem("lastfm", "lastFM.com"));
        networks.add(new NetworkItem("readernaut", "readernaut.com"));
        networks.add(new NetworkItem("friendfeed", "Friendfeed.com"));
        networks.add(new NetworkItem("web", "site.com"));
        person.setNetworkItems(networks);
        List<Address> address = new ArrayList<Address>();
        address.add(new Address("60 rue Camille desmoulins 94800 VILLEJUIF", Address.DEFAULT_ADDRESS));
        address.add(new Address("Le gué briand 35720 TRESSE", Address.PERSONAL_ADDRESS));
        address.add(new Address("2 rue des bourets Suresnes", Address.PROFESSIONNAL_ADDRESS));
        person.setAddresses(address);
        List<Tel> tel = new ArrayList<Tel>();
        tel.add(new Tel("0953868603", Tel.HOME_LANDLINE));
        tel.add(new Tel("0673116302", Tel.MOBILE_LINE));
        tel.add(new Tel("0299737423", Tel.PROFESSIONNAL_LINE));
        person.setTels(tel);
        List<Email> email = new ArrayList<Email>();
        email.add(new Email("de-sai_p@epita.fr", Email.PERSONAL_EMAIL));
        email.add(new Email("desaintsteban.p@sfeir.com", Email.PROFESSIONNAL_EMAIL));
        email.add(new Email(username, Email.UNKNOWN));
        person.setEmails(email);
        return person;        
    }
}
